// 实现求和1+2+3+...+n
function forLoop (n) {
  let res = 0
  for (let i = 1; i <= n; i++) {
    res += i
  }
  return res
}
console.log(forLoop(6))

function whileLoop (n) {
  let res = 0
  while (n >= 1) {
    res += n
    n--
  }
  return res
}
console.log(whileLoop(6))

function whileLoopII (n) {
  let res = 0
  let i = 1
  while (i <= n) {
    res += i
    i++
    i*=2
  }
  return res
}
console.log(whileLoopII(6))
